package br.com.android.pubclub.negocios;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;
import br.com.android.pubclub.basicas.Estabelecimento;
import br.com.android.pubclub.dados.EstabelecimentoAdapter;
import br.com.android.pubclub.dados.WsServicos;


public class ListaEstabelecimentosActivity extends Activity implements OnItemClickListener{

	
	List<Estabelecimento> estabelecimentos;
	private ListView listView;
	/* (non-Javadoc)
	 * @see android.support.v4.app.ListFragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
	 */
	/* (non-Javadoc)
	 * @see android.app.ListActivity#setListAdapter(android.widget.ListAdapter)
	 */

	


	@Override
	public void onResume() {
		super.onResume();
		refreshList();
	}
	
	@Override
	public void onItemClick(AdapterView<?> listview, View linha, 
			int posicao, long id) {
		//String nome = nomes[posicao];
		Toast.makeText(this, "Cliko", Toast.LENGTH_SHORT).show();
	}
	
	
	private void iniciarDownload() {
		try {
			estabelecimentos = new ArrayList<Estabelecimento>();
			Intent it = new Intent(this, WsServicos.class);
			it.putExtra("parametro", "consumirServiceListaEstabelecimento");			
			startActivityForResult(it, 1);			
			
			//Estabelecimento est1 = new. Estabelecimento("Carcara", "8130341629", "-8.1083479", "-34.9114718");
			//Estabelecimento est2 = new Estabelecimento("Ilha da Costa", "8130341111", "-8.1083479", "-34.9114718");
			//Estabelecimento est3 = new Estabelecimento("Entre Amigos", "8130342222", "-8.1083479", "-34.9114718");
			//estabelecimentos.add(est1);
			//estabelecimentos.add(est2);
			//estabelecimentos.add(est3);
			//refreshList();
		} catch (Exception vE) {
			vE.getMessage();
		}
		
	}

	@Override
	protected void onActivityResult(int pRequestCode, int pResultCode, Intent pData) {
		// TODO Auto-generated method stub
		super.onActivityResult(pRequestCode, pResultCode, pData);
		if ((pRequestCode == 1) && (pResultCode == RESULT_OK)){
			estabelecimentos = (ArrayList<Estabelecimento>) pData.getSerializableExtra("lista");
			refreshList();
		}
	}
	public void refreshList() {
		EstabelecimentoAdapter  adapter = new EstabelecimentoAdapter(this, estabelecimentos);
		//setListAdapter(adapter);
	}
	
	
		public interface ClicouNoEstabelecimentoListener {
		void clicouEmUmEstabelecimento(Estabelecimento est);
	}
	
}
